<?php
if($_GET['act'] == 'profile')
{
?>
<div id="indexcates">
        <div class="row-fluid" >
            <ul class="breadcrumb">
                <li>修改个人资料</li>
            </ul>
        </div>
            <?php
            if($_SESSION['sid']!=''){
                $query = "select * from ".DBPREFIX."member where id=".$_SESSION['sid'];
                $result =$db->query($query);
                $memberinfo = $db->fetch_array($result);
            }
            else{
                fs_showmsg('您还没有登陆!','?do=do');
            }
            ?>
        <div class="exam_list">
            <form action="#" method="post" name="addform" enctype="multipart/form-data">
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <input type="hidden" name="photo" value="<?php echo($memberinfo['photo']);?>" style="width:300px;" />
                    <tr>
                        <td align="center" width="20%">用户名:</td><td><input type="text" name="username" disabled="disabled" value='<?php echo $memberinfo['passport']?>'/><font color="red">*</font>此项不能修改</td>
                    </tr>
                    <tr>
                        <td align="center">真实姓名:</td><td><input type="text" name="realname" value='<?php echo $memberinfo['realname']?>'/></td>
                    </tr>
                     <?php 
                        if($memberinfo['type']==2){?>
                    <input type="hidden" name="lastphoto" value="<?php echo($memberinfo['photo']);?>" style="width:300px;" />
                    <tr> <td align="center">头像:</td>
                        <td><iframe frameborder="0" name="upload_frame" scrolling="no" src="backstage/admin_upload.php" width="280" onload="this.height=this.contentWindow.document.body.scrollHeight"></iframe></td>
                    </tr>
                    <?php }?>
<!--                    <?php
                    if($memberinfo['head']==''){
                        switch($memberinfo['type']){
                            case 0:
                        ?>
                        <tr>
                            <td align="center">个人头像:</td><td><img src="<?php echo 'resources/images/webmaster.png';?>" alt="用户头像" height="50" width="50" /></td>
                        </tr>
                        <?php
                        break;
                        ?>
                         <?php
                            case 2:
                        ?>
                        <tr>
                            <td align="center">个人头像:</td><td><img src="<?php echo 'resources/images/user3.png'?>" alt="用户头像" height="50" width="50" /></td>
                        </tr>
                        <?php
                        break;
                        ?>
                         <?php
                            case 3:
                        ?>
                        <tr>
                            <td align="center">个人头像:</td><td><img src="<?php echo 'resources/images/graduated.png';?>" alt="用户头像" height="50" width="50" /></td>
                        </tr>
                        <?php
                        break;
                        ?>
                         <?php
                            default:
                        ?>
                        <tr>
                            <td align="center">个人头像:</td><td><img src="<?php echo 'resources/images/none-pic.gif';?>" alt="用户头像" height="50" width="50" /></td>
                        </tr>
                        <?php
                        break;
                        }
                        }
                        else{
                            ?>
                        <tr>
                            <td align="center">个人头像:</td><td><img src="<?php echo $memberinfo['head']?>" alt="用户头像" height="50" width="50" /></td>
                        </tr>
                        <?php       
                        }
                        ?>
                    
                    <tr>  
                        <td align="center">上传新头像:</td><td><input type="file" id="head"  name="head" /><input type="submit" value="上传" name="submit"/>仅支持jpg,png,gif格式</a></td>
                    </tr>
                    -->
                    <tr>  
                        <td align="center">Email:</td><td><input type="text" id="email"  name="email" value='<?php echo $memberinfo['email']?>'/>
<!--                            <font color="red">未验证</font><a href="">验证Email</a>-->
                        </td>
                    </tr>
                    <tr> 
                        <td align="center">联系电话:</td><td><input type="text" id="tel" name="tel"  value='<?php echo $memberinfo['tel']?>'/></td>
                    </tr>
                    <tr>  
                        <td align="center">QQ:</td><td><input type="text" name="qq" value='<?php echo $memberinfo['qq']?>'/></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submit" value="提交修改"></td>
                    </tr>
                </table>
            </form>
        </div>   
    </div>
<?php
}
if($_GET['act'] == 'setpassword')
{
?>
<div id="indexcates">
        <div class="row-fluid" >
            <ul class="breadcrumb">
                <li>修改密码</li>
            </ul>
        </div>
            <?php
            if($_SESSION['sid']!=''){
                $query = "select * from ".DBPREFIX."member where id=".$_SESSION['sid'];
                $result =$db->query($query);
                $memberinfo = $db->fetch_array($result);
            }
            else{
                fs_showmsg('您还没有登陆!','?do=do');
            }
            ?>
        <div class="exam_list">
            <form action="#" method="post" onsubmit="return checkform()">
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr>
                        <td align="center" width="20%">用户名:</td><td><input type="text" name="username" disabled="disabled" value='<?php echo $memberinfo['passport']?>'/><font color="red">*</font>此项不能修改</td>
                    </tr>
                    <tr>
                        <td align="center">旧密码:</td><td><input type="text" name="oldpassword1" id="oldpassword1" /><input type="hidden" name="oldpassword2" value="<?php echo $memberinfo['password']?>"/></td>
                    </tr> 
                    <tr>  
                        <td align="center">新密码:</td><td><input type="password" name="newpassword1" id ="newpassword1" /></td>
                    </tr>
                    <tr>  
                        <td align="center">确认密码:</td><td><input type="password" name="newpassword2" id="newpassword2" /></td>
                    </tr>
 
                    <tr>
                        <td colspan="2"><input type="submit" name="submit2" value="提交修改"></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
<?php
}
if($_POST['submit']!=''&&$_SESSION['sid']){
  $realname = $_POST['realname'];
  $email = $_POST['email'];
  $tel = $_POST['tel'];
  $qq = $_POST['qq'];
  $photo = $_POST['photo'];
  $lastphoto = $_POST['lastphoto'];
  $update_query ="update ".DBPREFIX."member set realname='".$realname."',email='".$email."',tel='".$tel."',qq='".$qq."' where  id=".$_SESSION['sid'];
  $result  =$db->query($update_query);
  if($photo != '' && $photo !=$lastphoto){
        $update_query="update ".DBPREFIX."member set photo='".$photo."' where  id=".$_SESSION['sid'];
        $db->query($update_query);
        $file="backstage/".$lastphoto;  
        if (unlink($file)) {
//                               echo "The file was deleted successfully.", "n";
        } else {
//                               echo "The specified file could not be deleted. Please try again.", "n";
        }
    }
  if($result){
      fs_showmsg('信息修改成功!','?do=editaccount&act=profile');
  }
  else
  {
      fs_showmsg('信息修改失败!');
  }
}
if($_POST['submit2'] !=''){
    $oldpassword1 = $_POST['oldpassword1'];
    $oldpassword2 = $_POST['oldpassword2'];
    $newpassword1 = $_POST['newpassword1'];
    $newpassword2 = $_POST['newpassword2'];
    if(md5($oldpassword1)!=$oldpassword2){
        fs_showmsg('您输入的原密码有误,请重新输入!');
    }
    if($newpassword1!=$newpassword2)
    {
        fs_showmsg('两次密码输入不一致,请重新输入!');
    }
    $update_query = "update ".DBPREFIX."member set password='".md5($newpassword1)."' where id=".$_SESSION['sid'];
    $result  =$db ->query($update_query);
    if($result){
        session_unset();
        fs_showmsg('更新密码成功,请重新登录!','?do=do');
    }
    else{
        fs_showmsg('更新密码失败');
    }
}
?>